<template>
	<div>
		<el-breadcrumb v-if="levelList.length>1" separator="/">
			<el-breadcrumb-item :to="{ path: levelList[0].path }">{{ levelList[0].name }}</el-breadcrumb-item>
			<el-breadcrumb-item :to="{ path: levelList[1].path }">
				{{ levelList[1].name }}
			</el-breadcrumb-item>
		</el-breadcrumb>
		<el-breadcrumb v-else separator="/">
			<el-breadcrumb-item :to="{ path: levelList[0].path }">{{ levelList[0].name }}</el-breadcrumb-item>
		</el-breadcrumb>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				levelList: [],
			}
		},
		mounted() {
			this.$watch('$route', {
				deep: true,
				handler: function() {
					if(this.$route.name !== '首页') {
						this.levelList = this.$route.matched.filter(item => item.name)
					} else {
						this.levelList = [{
							path: '',
							name: '首页'
						}]
					}
				}
			})
		},
		created() {
			console.log('this.$route', this.$route)
			if(this.$route.name !== '首页') {
				this.levelList = this.$route.matched.filter(item => item.name)
			} else {
				this.levelList = [{
					path: '',
					name: '首页'
				}]
			}
		}
	}
</script>

<style scoped>

</style>